<template>
    <div class="pageContainer">
        <el-form inline>
            <div class="searchWarp">
                <CText title="编码" v-model="params.code" ></CText>
                <CText title="名称" v-model="params.name"></CText>
                <div class="schLine">
                    <CBtn @click="search(1)">查询</CBtn>
                </div>
            </div>
        </el-form>
        <div class="treeTable">
            <div style="flex:1;">
                <el-table border :data="tableData" :max-height="maxHeight">
                    <el-table-column prop="code" label="编码"></el-table-column>
                    <el-table-column prop="name" label="名称"></el-table-column>
                    <el-table-column prop="prop_val" label="规格"></el-table-column>
                    <el-table-column prop="orgName" label="公司"></el-table-column>
                    <el-table-column prop="stock_num" label="库存"></el-table-column>
                    <el-table-column prop="cur_price" label="售价"></el-table-column>
                </el-table>
                <el-pagination class="tablePaging" @size-change="changeSize" @current-change="changePage" :current-page="curPage"
                    :page-sizes="pageSizes" :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper" :total="total">
                </el-pagination>
            </div>
        </div>
    </div>
</template>

<script>
import pagingMixin from '@/mixin/pagingMixin'
export default {
    mixins: [pagingMixin],
    data() {
        return {
            maxHeight: "640px",
            curPage: 1,
            pageSize: 20,
            total: 0,
            tableData: [],
            pageSizes: [10,20,30,40],
            params: {
                code: "",
                name: ""
            }
        }
    },
    created() {
        this.search();
    },
    methods: {
        changePage(page) {
            this.curPage = page;
            this.search();
        },
        changeSize(size) {
            this.pageSize = size;
            this.search();
        },
        search(page) {
            if(page) {
                this.curPage = page;
            }
            this.$scx.stockNow({
                    curPage: this.curPage, 
                    pageSize: this.pageSize,
                    ...this.params
                }).then(res => {
                this.tableData = res.data.rows;
                this.total = res.data.count;
            })
        }
    }
}
</script>

<style lang="scss" scoped>
.roleWarp {
    display: flex;
    flex-wrap: wrap;
}
</style>